package tanxin;

import java.util.Arrays;
import java.util.Comparator;

public class leetCode452_findMinArrowShots {
    public static void main(String[] args) {
        leetCode452_findMinArrowShots b = new leetCode452_findMinArrowShots();
        int[][] bb= {{10,16},{7,8},{1,6},{7,12}};
        int minArrowShots2 = b.findMinArrowShots2(bb);
        System.out.println(minArrowShots2);
    }
    public int findMinArrowShots2(int[][] points) {
        if(points == null || points.length == 0) return 0;
        Arrays.sort(points, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if(o1[0] > o2[0]){
                    return 1;
                }else if(o1[0] < o2[0]){
                    return -1;
                }else{
                    return 0;
                }
            }
        });
        int count = 1;
        int end = points[0][1];
        for (int[] point : points) {
            int start = point[0];
            if(start > end){
                count++;
                end = point[1];
            }

        }
        return count;


    }
}
